package cn.edu.lzzy.entities;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;

import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 课程实体类
 */
@Entity
public class Course extends BasicEntity{
    private String name;//课程名
    private String description;//课程说明
    private String cover;
    private Date createTime;//创建时间
    private Date updateTime;//更新时间
    private boolean isOpen;//开放状态
    @ManyToOne
    private User teacher;//任课教师

    @ManyToMany
    private List<User> students=new ArrayList<>();//学生

    @OneToMany(mappedBy = "course")
    private List<Chapter> chapters=new ArrayList<>();//章节

    @OneToMany(mappedBy = "course")
    private  List<Applicant> applicants=new ArrayList<>();//学生申请

    public Course() {
        createTime=new Date();
        updateTime=createTime;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getCover() {
        return cover;
    }

    public void setCover(String cover) {
        this.cover = cover;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public boolean isOpen() {
        return isOpen;
    }

    public void setOpen(boolean open) {
        isOpen = open;
    }

    public User getTeacher() {
        return teacher;
    }

    public void setTeacher(User teacher) {
        this.teacher = teacher;
    }

    @JsonIgnore
    public List<User> getStudents() {
        return students;
    }

    public void setStudents(List<User> students) {
        this.students = students;
    }
    @JsonBackReference
    public List<Chapter> getChapters() {
        return chapters;
    }

    public void setChapters(List<Chapter> chapters) {
        this.chapters = chapters;
    }
    @JsonBackReference
    public List<Applicant> getApplicants() {
        return applicants;
    }

    public void setApplicants(List<Applicant> applicants) {
        this.applicants = applicants;
    }
}
